﻿<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
  
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>You own WebDAV server </title>
    <meta name="viewport" content="width=device-width">
    <meta name="title" content="You own WebDAV server ">
    <meta name="generator" content="docfx 2.16.2.2">
    
    <link rel="shortcut icon" href="../favicon.ico">
    <link rel="stylesheet" href="../styles/docfx.vendor.css">
    <link rel="stylesheet" href="../styles/docfx.css">
    <link rel="stylesheet" href="../styles/main.css">
    <meta property="docfx:navrel" content="../toc.html">
    <meta property="docfx:tocrel" content="toc.html">
    
    
  </head>
  <body data-spy="scroll" data-target="#affix">
    <div id="wrapper">
      <header>
        
        <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>
              
              <a class="navbar-brand" href="../index.html">
                <img id="logo" class="svg" src="../logo.svg" alt="">
              </a>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
              <form class="navbar-form navbar-right" role="search" id="search">
                <div class="form-group">
                  <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
                </div>
              </form>
            </div>
          </div>
        </nav>
        
        <div class="subnav navbar navbar-default">
          <div class="container hide-when-search" id="breadcrumb">
            <ul class="breadcrumb">
              <li></li>
            </ul>
          </div>
        </div>
      </header>
      <div role="main" class="container body-content hide-when-search">
        
        <div class="sidenav hide-when-search">
          <a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
          <div class="sidetoggle collapse" id="sidetoggle">
            <div id="sidetoc"></div>
          </div>
        </div>
        <div class="article row grid-right">
          <div class="col-md-10">
            <article class="content wrap" id="_content" data-uid="">
              <h1 id="you-own-webdav-server">You own WebDAV server</h1>
              
<p>This walk-through shows how to create your own WebDAV server using Visual Studio 2017.</p>
<h1 id="create-the-basic-project">Create the basic project</h1>
<p>The easiest (and currently only supported) way to create a WebDAV server
is using a ASP.NET Core project as host.</p>
<ol>
<li><p>Create the ASP.NET Core project</p>
<p><img src="../images/walk-through/01-create-project.png" alt="screenshot"></p>
</li>
<li><p>Select the WebAPI template</p>
<p><img src="../images/walk-through/02-select-webapi.png" alt="screenshot"></p>
</li>
</ol>
<h1 id="configure-the-webdav-nuget-repository-optional">Configure the WebDAV NuGet repository (optional)</h1>
<ol>
<li><p>Open the package manager setup</p>
<p><img src="../images/walk-through/03-package-manager-setup.png" alt="screenshot"></p>
</li>
<li><p>Add the package source</p>
<p>The package source for the WebDAV server is (until release) on <a href="https://www.myget.org/feed/Packages/webdav-server">MyGet</a>. The URL is for the NuGet v3 feed is <a href="https://www.myget.org/F/webdav-server/api/v3/index.json">https://www.myget.org/F/webdav-server/api/v3/index.json</a>.</p>
<p><img src="../images/walk-through/03-webdav-server-nuget-repository.png" alt="screenshot"></p>
</li>
</ol>
<h1 id="add-the-webdav-nuget-packages">Add the WebDAV NuGet packages</h1>
<p>This are the packages that must be installed:</p>
<ul>
<li><p><a href="https://www.myget.org/feed/webdav-server/package/nuget/FubarDev.WebDavServer">FubarDev.WebDavServer</a></p>
<p> This is the main package containing the WebDAV implementation.</p>
</li>
<li><p><a href="https://www.myget.org/feed/webdav-server/package/nuget/FubarDev.WebDavServer.FileSystem.DotNet">FubarDev.WebDavServer.FileSystem.DotNet</a></p>
<p> This package contains the <a class="xref" href="https://msdn.microsoft.com/en-us/library/system.io(v=vs.110).aspx">System.IO</a> based file system implementation.</p>
</li>
<li><p><a href="https://www.myget.org/feed/webdav-server/package/nuget/FubarDev.WebDavServer.Props.Store.TextFile">FubarDev.WebDavServer.Props.Store.TextFile</a></p>
<p> This package stores the dead properties in a JSON file.</p>
</li>
<li><p><a href="https://www.myget.org/feed/webdav-server/package/nuget/FubarDev.WebDavServer.Locking.InMemory">FubarDev.WebDavServer.Locking.InMemory</a></p>
<p> This is the implementation of the locking that doesn&#39;t persist the information about the active locks.</p>
</li>
<li><p><a href="https://www.myget.org/feed/webdav-server/package/nuget/FubarDev.WebDavServer.AspNetCore">FubarDev.WebDavServer.AspNetCore</a></p>
<p> This package contains the glue between ASP.NET Core and the WebDAV server.</p>
</li>
</ul>
<p><img src="../images/walk-through/04-packages.png" alt="screenshot"></p>
<p>Finally, we should install some remaining package updates.</p>
<p><img src="../images/walk-through/05-update-packages.png" alt="screenshot"></p>
<h1 id="create-the-webdav-controller">Create the WebDAV controller</h1>
<ol>
<li><p>Rename the <code>ValuesController.cs</code> to <code>WebDavController.cs</code></p>
<p><img src="../images/walk-through/06-rename-controller.png" alt="screenshot"></p>
</li>
<li><p>Replace the content of <code>WebDavController.cs</code> with the following:</p>
<pre><code class="lang-csharp"> using System;

 using FubarDev.WebDavServer;
 using FubarDev.WebDavServer.AspNetCore;

 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Logging;

 namespace TestWebDavServer.Controllers
 {
     [Route(&quot;{*path}&quot;)]
     public class WebDavController : WebDavControllerBase
     {
         public WebDavController(IWebDavContext context, IWebDavDispatcher dispatcher, ILogger&lt;WebDavIndirectResult&gt; responseLogger = null)
             : base(context, dispatcher, responseLogger)
         {
         }
     }
 }
</code></pre><p> <img src="../images/walk-through/07-modify-controller.png" alt="screenshot"></p>
</li>
</ol>
<h2 id="explanation">Explanation</h2>
<p>This controller uses the base controller class from <a class="xref" href="../api/FubarDev.WebDavServer.AspNetCore.html">FubarDev.WebDavServer.AspNetCore</a>. This
controller contains everything that&#39;s needed for a WebDAV server class 1,2 implementation.</p>
<p>The <a class="xref" href="../api/FubarDev.WebDavServer.IWebDavContext.html">IWebDavContext</a> is the request context (similar to the <code>HttpContext</code> used in ASP.NET Core). It is used to query some basic information about the current request.</p>
<p>The <a class="xref" href="../api/FubarDev.WebDavServer.IWebDavDispatcher.html">IWebDavDispatcher</a> is the interface to the main WebDAV server functionality.</p>
<h1 id="configure-the-servies">Configure the servies</h1>
<p>Replace in <code>Startup.cs</code> the <code>.AddMvc()</code> in function <code>ConfigureServices</code> with the following code:</p>
<pre><code class="lang-csharp">.Configure&lt;DotNetFileSystemOptions&gt;(
    opt =&gt;
    {
        opt.RootPath = Path.Combine(Path.GetTempPath(), &quot;webdav&quot;);
        opt.AnonymousUserName = &quot;anonymous&quot;;
    })
.AddScoped&lt;IPropertyStoreFactory, TextFilePropertyStoreFactory&gt;()
.AddSingleton&lt;IFileSystemFactory, DotNetFileSystemFactory&gt;()
.AddSingleton&lt;ILockManager, InMemoryLockManager&gt;()
.AddMvcCore()
.AddAuthorization()
.AddWebDav();
</code></pre><p><img src="../images/walk-through/09-after-replace.png" alt="screenshot"></p>
<h2 id="explanation-1">Explanation</h2>
<p>The configuration of <code>DotNetFileSystemOptions</code> uses the <code>%TEMP%\webdav</code> folder as root folder. It also specifies that the unauthenticated user always gets the name <code>anonymous</code>.</p>
<p>This code also adds some required services:</p>
<ul>
<li><p><a class="xref" href="../api/FubarDev.WebDavServer.Props.Store.IPropertyStoreFactory.html">IPropertyStoreFactory</a> is the interface used for getting an <a class="xref" href="../api/FubarDev.WebDavServer.Props.Store.IPropertyStore.html">IPropertyStore</a> for an <a class="xref" href="../api/FubarDev.WebDavServer.FileSystem.IFileSystem.html">IFileSystem</a>.</p>
</li>
<li><p><a class="xref" href="../api/FubarDev.WebDavServer.FileSystem.IFileSystemFactory.html">IFileSystemFactory</a> is the unterface used for getting an <a class="xref" href="../api/FubarDev.WebDavServer.FileSystem.IFileSystem.html">IFileSystem</a> for the currently authenticated <a class="xref" href="https://msdn.microsoft.com/en-us/library/system.security.principal.iprincipal(v=vs.110).aspx">IPrincipal</a>.</p>
</li>
<li><p><a class="xref" href="../api/FubarDev.WebDavServer.Locking.ILockManager.html">ILockManager</a> is used for the coordination of WebDAV locks.</p>
</li>
</ul>
<h1 id="add-ntlm-authentication">Add NTLM authentication</h1>
<p>To allow <code>NTLM</code> (or <code>Negotiate</code>) authentication, the following steps must be done:</p>
<ol>
<li><p>Add the <code>Microsoft.AspNetCore.Authentication</code> package</p>
<p><img src="../images/walk-through/08-add-auth-package.png" alt="screenshot"></p>
</li>
<li><p>Add the <code>[Authorize]</code> attribute to the <code>WebDavController</code></p>
<p><img src="../images/walk-through/10-add-authorize-controller-attribute.png" alt="screenshot"></p>
</li>
<li><p>Replace in <code>Program.cs</code> the <code>.UseKestrel()</code> with the WebListener</p>
<pre><code class="lang-csharp">     .UseWebListener(opt =&gt;
     {
         opt.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.NTLM;
         opt.ListenerSettings.Authentication.AllowAnonymous = true;
     })
</code></pre></li>
<li><p>Remove the IIS integration</p>
</li>
</ol>
<p>Now, your <code>Program.cs</code> file should like like this:</p>
<p><img src="../images/walk-through/10-remove-iis-integration.png" alt="screenshot"></p>
<h1 id="disable-the-automatic-browser-launch-at-application-start">Disable the automatic browser launch at application start</h1>
<p>To disable the automatic browser launch, you have to set the <code>launchBrowser</code> entry in the <code>launchSettings.json</code> file (can befound under <code>Properties</code>) to <code>false</code>.</p>
<p>Before:</p>
<p><img src="../images/walk-through/11-before-browser-disable.png" alt="screenshot"></p>
<p>After:</p>
<p><img src="../images/walk-through/11-after-browser-disable.png" alt="screenshot"></p>
<h1 id="change-the-start-project-important">Change the start project (<strong>important!</strong>)</h1>
<p>You must change the start project from <code>IIS Express</code> to <code>TestWebDavServer</code> (your test project). Otherwise, using the <code>NTLM</code> authentication configured above, doesn&#39;t work.</p>
<p><img src="../images/walk-through/12-start-server.png" alt="screenshot"></p>
<h1 id="running-the-test-server">Running the test server</h1>
<p>When you start the test server, you can see the WebDAV url in the console window:</p>
<p><img src="../images/walk-through/13-use-explorer-with-url.png" alt="screenshot"></p>
<p>Enter this URL into the Windows Explorers address bar and you should be able to connect to the server.</p>

            </article>
          </div>
          
          <div class="hidden-sm col-md-2" role="complementary">
            <div class="sideaffix">
              <div class="contribution">
                <ul class="nav">
                  <li>
                    <a href="https://github.com/FubarDevelopment/WebDavServer/blob/master/articles/getting-started.md/#L1" class="contribution-link">Improve this Doc</a>
                  </li>
                </ul>
              </div>
              <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
              <!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
              </nav>
            </div>
          </div>
        </div>
      </div>
      
      <footer>
        <div class="grad-bottom"></div>
        <div class="footer">
          <div class="container">
            <span class="pull-right">
              <a href="#top">Back to top</a>
            </span>
            <span>Copyright © 2016-2017 Fubar Development Junker<br>Generated by <strong>DocFX</strong></span>
            
          </div>
        </div>
      </footer>
    </div>
    
    <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
    <script type="text/javascript" src="../styles/docfx.js"></script>
    <script type="text/javascript" src="../styles/jquery.min.js"></script>
    <script type="text/javascript" src="../styles/main.js"></script>

    <div id='lightbox'></div>
  </body>
</html>
